﻿#include<iostream>
using namespace std;

#define SoftName "EDY"
#define SoftVersion "2.0"

int main() {
	string str, str1, str2, str3, str4;
	str = string{ "123" } + "123";
	cout << str << endl; //123123

	str1 = "abc" + string{ "123" };
	cout << str1 << endl;//abc123

	str2 = "abc" + ("abc" + string{ "123" });
	cout << str2 << endl;//abcabc123

	str3 = str3 + "asdf";
	cout << str3 << endl;//asdf

	str3 += "nba" + string{ "sss" };
	cout << str3 << endl;//nbasss

	str4 = "123""123";//这种方式要两个常量才可以
	str4 = SoftName SoftVersion;
	cout << str4 << endl;//EDY2.0

	char a[2]{ "1" };
	string str5{ "sadf" };
	str5 += a;
	cout << str5 << endl;//sadf1
	str5 += a + 'o';//这里相当于str5 += char(a+'o')，也就是说a的ASCII码与'o'的ASCII码相加

	string str6{ "123" };
	str6.append(" 456").append(" 789").append(" 456", 2);//append的用法和初始化提到的一样，如append(" 456",2)
	cout << str6 << endl;//123 456 789 4

	//str1 = "abc" + "123" ;

	string str7;
	str7 = str6.substr(7).substr(2);//从第7位开始截断，substr的用法和初始化提到的一样
	cout << str7 << endl;//89 4

	string str8{ "123" };
	cout << str8.length() << endl;//3

	string str9{ "123撒打发" };
	cout << str9.length() << endl;//9，因为length()函数中文算作2字节

	string id{ "id=;" };
	id.insert(3, "testId");//第3个位置插入testId
	cout << id << endl;//id=testId;

	id.insert(3, "killertestid", 6, 6);//第3个位置插入killertestid的第6个开始长度为6的字符串
	cout << id << endl;//id=testidtestId;

	id.insert(3, "killertestid", 6);//第3个位置插入killertestid的第1个开始长度为6的字符串
	cout << id << endl;//id=killertestidtestId;

	id.insert(3, 6, '*');//第三个位置插入6个*
	cout << id << endl;//id=******killertestidtestId;

}